﻿using AutoMapper;
using MediatR;
using S.Services.SheepMale.Api.Application.Command.SheepMaleCommand;
using S.Services.SheepMale.Domain.PurchaseSales;
using S.Services.SheepMale.Infrastructure;

namespace S.Services.SheepMale.Api.Application.CommandHandler.SheepMaleCommandHandler
{
    public class SheepFatherNewExamineCommandHandler : IRequestHandler<SheepFatherNewExamineCommand, int>
    {
        private readonly IRepository<SheepMaleInfo> repository;

        private readonly IMapper mapper;
        public SheepFatherNewExamineCommandHandler(IRepository<SheepMaleInfo> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<int> Handle(SheepFatherNewExamineCommand request, CancellationToken cancellationToken)
        {
            var result = repository.GetAsync(request.maleId).Result;
            result.ExamineDate = null;
            result.ExamineBy = null;
            result.ExamineType = false;
            return await repository.UpdateAsync(result);
        }
    }
}
